package cvar.model.transaction;

import java.util.Set;
import java.util.TreeSet;

public class Product {

  enum Type {
    DAILY(24),
    WEEKLY(168),
    MONTHLY(720),
    QUARTERLY(2136);
    
    private final int duration_;
    
    Type(int duration) {
      duration_ = duration;
    }
    
    int getDuration() {
      return duration_;
    }
  }


  private Type type_;
  private int startHour_;
  private int iteration_;

  private Product(Type type, int startHour, int iteration) {
    type_ = type;
    startHour_ = startHour;
    iteration_ = iteration;
  }


  public static Product makeProduct(Type type, int startHour, int iteration) {
    if (Type.QUARTERLY == type || iteration >= 3) {
      return new Product(type, startHour, iteration);
    }
    return null;
  }


  public Set<Integer> getHours() {
    Set<Integer> hours = new TreeSet<Integer>();
    for (int i = startHour_; i < startHour_ + type_.getDuration() * iteration_; ++i)
      hours.add(i);
    return hours;
  }


  public String getName() {
    return type_.toString() + "_" + startHour_ + "_" + iteration_;
  }

}
